package com.shujia.wyh.day21;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
        HashMap案例
            HashMap<String,String>

 */
public class HashMapDemo1 {
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        //向集合中添加元素
        map.put("霞", "洛");
        map.put("寒冰", "蛮王");
        map.put("塞纳", "卢锡安");
        map.put("卡特", "盖伦");
        map.put("霞", "洛3");

        //遍历集合
        //方式1：根据键找值
        Set<String> keys = map.keySet();
        for (String key : keys) {
            String value = map.get(key);
            System.out.println(key + ":" + value);
        }
        System.out.println("=========================================");
        //方式2：根据键值对找键和值
        Set<Map.Entry<String, String>> entrySet = map.entrySet();
        for (Map.Entry<String, String> keyValue : entrySet) {
            String key = keyValue.getKey();
            String value = keyValue.getValue();
            System.out.println(key + "---" + value);
        }


    }
}
